package xyz.scootaloo.oj.leetcode;

import java.util.Arrays;

/**
 * 未完成
 * @author flutterdash@qq.com
 * @since 2021/4/5 14:26
 */
public class P28 {

    public int strStr(String haystack, String needle) {
        int[] next = getPartialMatchArray(needle);
        int pos = 0;
        for (int i = 0; i<haystack.length(); i++) {
//            while (haystack.charAt(i))
        }
        return -1;
    }

    /**
     * pm[i] 表示字符串长度为 i+1 的前缀里 (除本身外) 最长相等的前后缀长度
     * input:  b  b  b  b  a  b
     *    dp:  0  1  2  3  0  1
     * input:  a  b  c  a  b  c
     *    dp:  0  0  0  1  2  3
     * @param input ignore
     * @return ignore
     */
    private int[] getPartialMatchArray(String input) {
        int len = input.length();
        int[] pm = new int[len];
        if (len == 0)
            return pm;
        for (int i = 1; i<len; i++) {
            if (input.charAt(i) == input.charAt(pm[i - 1])) {
                pm[i] = pm[i - 1] + 1;
            }
        }

        // 滑动 pm 数组
        System.arraycopy(pm, 0, pm, 1, len - 1);
        pm[0] = -1;

        return pm;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new P28().getPartialMatchArray("bbbbab")));
        System.out.println(Arrays.toString(new P28().getPartialMatchArray("abcabc")));
    }

}
